//
//  UIButton+CZAddition.m
//  SinaWeibo
//
//  Created by 张晗 on 2017/1/26.
//  Copyright © 2017年 zhanghan. All rights reserved.
//

#import "UIButton+CZAddition.h"

@implementation UIButton (CZAddition)

+ (instancetype)cz_textButton:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor selectedColor:(UIColor *)selectedColor {
    return [self buttonWithTitle:title fontSize:fontSize normalColor:normalColor hightlightedColor:nil selectedColor:selectedColor imageName:nil backgroundImageName:nil];
}

+ (instancetype)cz_textButton:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor hightlightedColor:(UIColor *)hightlightedColor {
    return [self cz_textButton:title fontSize:fontSize normalColor:normalColor hightlightedColor:hightlightedColor backgroundImageName:nil];
}

+ (instancetype)cz_textButton:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor hightlightedColor:(UIColor *)hightlightedColor backgroundImageName:(NSString *)backgroundImageName {
    return [self buttonWithTitle:title fontSize:fontSize normalColor:normalColor hightlightedColor:hightlightedColor selectedColor:nil imageName:nil backgroundImageName:backgroundImageName];
}

+ (instancetype)cz_imageButton:(NSString *)imageName backgroundImageName:(NSString *)backgroundImageName {
    return [self buttonWithTitle:nil fontSize:17 normalColor:nil hightlightedColor:nil selectedColor:nil imageName:imageName backgroundImageName:backgroundImageName];
}

+ (instancetype)buttonWithTitle:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor hightlightedColor:(UIColor *)hightlightedColor selectedColor:(UIColor *)selectedColor  imageName:(NSString *)imageName backgroundImageName:(NSString *)backgroundImageName {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setTitleColor:normalColor forState:UIControlStateNormal];
    [button setTitleColor:hightlightedColor forState:UIControlStateHighlighted];
    [button setTitleColor:selectedColor forState:UIControlStateSelected];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont systemFontOfSize:fontSize]];
    [button sizeToFit];
    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:backgroundImageName] forState:UIControlStateNormal];
    
    return button;
}

- (void)setImage:(UIImage *)image backgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state {
    [self setImage:image forState:state];
    [self setBackgroundImage:backgroundImage forState:state];
}

@end
